/*
################################################################################
#                                                                               
# Name : UserData.java       
# Author: Zhou Tao                                             
# Desc : UserData is used to load login session information.
#                                                                               
#                                                                               
# (C) COPYRIGHT IBM Corporation 2013                                      
# All Rights Reserved.                                                          
#                                                                               
# Licensed Materials-Property of IBM                                            
#                                                                               
################################################################################ 
*/
package com.ecar.mp.servlet;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Date;
import java.util.List;

public class UserData implements Serializable {

	private int id;
	private String username;
	private String phone;
	private String email;
	private int status;
	private String empno; 			// 工号
	private String name; 			// 名字
	private int gender; 			// 性别
	private Date birth;				// 生日
	private String department;		// 部门
	private String position;		// 职务
	private List<String> roles;
	private List<String> auths;

	public UserData() {
	}

	public UserData(
			int id,
			String username,
			String phone,
			String email,
			int status,
			String empno,
			String name,
			int gender,
			Date birth, String department, String position) {
		this.id = id;
		this.username = username;
		this.phone = phone;
		this.email = email;
		this.status = status;
		this.empno = empno;
		this.name = name;
		this.gender = gender;
		this.birth = birth;
		this.department = department;
		this.position = position;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getEmpno() {
		return empno;
	}

	public void setEmpno(String empno) {
		this.empno = empno;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public Date getBirth() {
		return birth;
	}

	public void setBirth(Date birth) {
		this.birth = birth;
	}

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public List<String> getRoles() {
		return roles;
	}

	public void setRoles(List<String> roles) {
		this.roles = roles;
	}

	public List<String> getAuths() {
		return auths;
	}

	public void setAuths(List<String> auths) {
		this.auths = auths;
	}

	public String toString() {
		String s = "";
		Field[] fds = this.getClass().getDeclaredFields();

		for (Field f : fds) {
			int m = f.getModifiers();
			if (m == 17 || m == 1) { // only show public field

				String fieldName = f.getName();
				Object fieldValue;
				try {
					fieldValue = f.get(this);
					if (fieldValue instanceof String[]) {
						String[] tmp = (String[]) fieldValue;
						String tmpStr = "[";
						int size = tmp.length;
						for (int j = 0; j < size; ++j) {
							if (j < size - 1) {
								tmpStr += "\"" + tmp[j] + "\",";
							} else {
								tmpStr += "\"" + tmp[j] + "\"]";
							}
						}
						fieldValue = tmpStr;
					}
					s += fieldName + " = " + fieldValue + "\n";
				} catch (IllegalArgumentException | IllegalAccessException e) {
					e.printStackTrace();
				}
			}
		}
		return s;
	}

}
